package cn.linlane.entity.sys;

import cn.linlane.entity.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * 用户信息
 */
@Entity
@Getter
@Setter
@Table(name = "sys_user")
@Where(clause = " is_delete = false")
public class SysUser extends BaseEntity {

    @NonNull
    @Column(name = "account", unique = true)
    @ApiModelProperty(value = "账户")
    private String account;

    @Column(name = "username")
    @ApiModelProperty(value = "用户名")
    private String username;

    @NonNull
    @Column(name = "password")
    @ApiModelProperty(value = "密码")
    private String password;

    @Column(name = "store_name")
    @ApiModelProperty(value = "所在门店名称")
    private String storeName;

    @Column(name = "store_code")
    @ApiModelProperty(value = "门店编号")
    private String storeCode;

    @ElementCollection(fetch = FetchType.EAGER)
    @Column(name = "data_permition")
    @ApiModelProperty(value = "数据权限")
    private Set<String> dataPermition = new HashSet<>();

    @Column(name = "is_enabled")
    @ApiModelProperty(value = "是否可用，true:可用，false:禁用")
    private Boolean isEnabled = true;

    @JsonIgnore
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "user_sys_role")
    private Set<SysRole> sysRoles;

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + id;
        result = prime * result + ((account == null) ? 0 : account.hashCode());
        result = result + dataPermition.hashCode();
        return result;
    }

}
